package cn.edu.sziit.bbs.interceptor;

import cn.edu.sziit.bbs.model.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入拦截器");
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        if (!user.getUserLevel().equals("admin")) {
            System.out.println("权限不足");
            response.sendRedirect("/login");
            return false;
        }
        System.out.println("管理员已经登录");
        return true;
    }
}
